<template>
  <el-tree
    :data="data"
    ref="departTree"
    node-key="kid"
    default-expand-all
    :props="defaultProps"
    @node-click="handleNodeClick"
    :current-node-key="currentKey"
  ></el-tree>
</template>
<script>
import { baseUrl } from "@/config/env";
var urls = {
  list: baseUrl + "/cp/dept/au-dept/tree"
};
export default {
  data() {
    return {
      data: [],
      defaultProps: {
        children: "children",
        label: "name"
      },
      currentKey: null
    };
  },
  mounted: function() {
    this.fetch();
  },
  methods: {
    handleNodeClick(data) {
      this.currentKey = data.objectId;
      this.$emit("load", this.currentKey);
    },
    fetch() {
      axios.get(urls.list).then(res => {
        this.data = res.data.result;
        this.handleNodeClick(this.data[0]);
      });
    }
  }
};
</script>